﻿// ConfigPage.cpp : 实现文件
//

#include "stdafx.h"
#include "SplitDemo.h"
#include "ConfigPage.h"
#include "afxdialogex.h"
#include "MainFrm.h"
// #define BYTEID	100
// #define WORDID	200
// #define BITID	300
// #define MULTIBITID	400
// #define INTERNALINTWO	2
// #define INTERNALTOOK	20
// #define SHORTNAMELENGTH 70
// #define DROPLISTHEIGHT 8
// #define DIRECTID	400
// #define MAXDIRECTNAME 60 
void makeRect(int X, int Y, int W, int H, CRect& r)
{
	r.top = Y;
	r.left = X;
	r.bottom = Y + H;
	r.right = X + W;
}
void CConfigPage::MyGetRect(int nID, LPRECT r)
{
	CWnd *pWnd = GetDlgItem(nID);
	pWnd->GetWindowRect(r);
	ScreenToClient(r);
}
// CConfigPage 对话框

IMPLEMENT_DYNAMIC(CConfigPage, CPropertyPage)

CConfigPage::CConfigPage()
	: CPropertyPage(CConfigPage::IDD)
{
	m_nPageIdx = 0xffffffff;
}

CConfigPage::~CConfigPage()
{
}
void CConfigPage::SetPageIdx(int nPage)
{
	m_nPageIdx = nPage;
	m_psp.dwFlags = m_psp.dwFlags | PSP_USETITLE;
	m_psp.pszTitle = g_wszPageTitle[nPage-1];
}
void CConfigPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CConfigPage, CPropertyPage)
END_MESSAGE_MAP()


// CConfigPage 消息处理程序


BOOL CConfigPage::OnInitDialog()
{
	CPropertyPage::OnInitDialog();
	


	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常:  OCX 属性页应返回 FALSE
}
void CConfigPage::EnableChildWindow(CWnd* pCurWnd,BOOL bIsEnable)
{
	
	CWnd* pwndChild = pCurWnd->GetWindow(GW_CHILD);
	
	while (pwndChild)
	{
		//EnableChildWindow(pwndChild,bIsEnable);
		pwndChild->EnableWindow(bIsEnable);
		pwndChild = pwndChild->GetNextWindow();
	
	}

}

BOOL CConfigPage::OnCommand(WPARAM wParam, LPARAM lParam)
{
	int i, j, k;
	CButton *pRadio;
	int begin = (BITID + 32), end = (BITID + 32);
	i = wParam;
	int radioidx = 0;
	if (i >= 332 && i < 362)
	{
		for (k = 0; k < nMultiCnt; k++)
		{
			
			
			if (((pConfigBitMultiValue + k)->cType == 1) && ((pConfigBitMultiValue + k)->nPage == m_nPageIdx))
			{
				end += (pConfigBitMultiValue + k)->nCnt;

				for (j = 0; j < (pConfigBitMultiValue + k)->nCnt; j++)
				{
					if ((i >=begin) && (i <  end))
					{
						pRadio = (CButton*)GetDlgItem(BITID + 32 + radioidx);
						if (i == BITID + 32 + radioidx)
						{
							
							pRadio->SetCheck(1);
						}
						else
						{
							pRadio->SetCheck(0);
						}
						
						if (j == (pConfigBitMultiValue + k)->nCnt - 1)
						{
							
							
								return CPropertyPage::OnCommand(wParam, lParam);

							
						}
					}
					radioidx++;
					
				}
				begin += (pConfigBitMultiValue + k)->nCnt;
				
			}
			
		}
	
	
	}
	//
	return CPropertyPage::OnCommand(wParam, lParam);
}


BOOL CConfigPage::OnKillActive()
{
	//CMainFrame *pMainframe = (CMainFrame *)AfxGetApp()->m_pMainWnd;

	int k = 0, j = 0;
	TCHAR wsztemp[32];
	//edit
	for (k = 0; k < nSingleIntCnt; k++)
	{
		if (((pConfigEditOneValue + k)->nPage == m_nPageIdx))
		{
			
			(pConfigEditOneValue + k)->pEdit->GetWindowTextW(wsztemp,sizeof(wsztemp));
			swscanf_s(wsztemp, L"%x", &(pConfigEditOneValue + k)->nValue);
			g_ConfigData.nData[(pConfigEditOneValue + k)->nPos] = (pConfigEditOneValue + k)->nValue;
			delete (pConfigEditOneValue + k)->pEdit;
			(pConfigEditOneValue + k)->pEdit = NULL;
			
		}

	}
	//多选框，RADIO和CHECK
	for (k = 0; k < nMultiCnt; k++)
	{

		if (((pConfigBitMultiValue + k)->nPage == m_nPageIdx))
		{

			(pConfigBitMultiValue + k)->nValue = 0;
			for (j = 0; j < (pConfigBitMultiValue + k)->nCnt; j++)
			{
				if ((pConfigBitMultiValue + k)->pButton[j]->GetCheck())
				{
					(pConfigBitMultiValue + k)->nValue |= (1 << j);
				}
				delete (pConfigBitMultiValue + k)->pButton[j];
				(pConfigBitMultiValue + k)->pButton[j] = NULL;
			}

			g_ConfigData.nData[(pConfigBitMultiValue + k)->nPos] = (pConfigBitMultiValue + k)->nValue;


		}

	}
	return CPropertyPage::OnKillActive();
}


BOOL CConfigPage::OnSetActive()
{
	//return 1;
	CWnd* pWnd = GetDlgItem(IDC_EDIT1);
	//CWnd* pWnd ;
	DWORD dwEDITEXTYPE = pWnd->GetExStyle();
	DWORD BoxStyle = pWnd->GetStyle() | WS_VISIBLE;

	DWORD StatStyle = WS_CHILD | WS_VISIBLE;
	DWORD GroupStyle = WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_TABSTOP;
	DWORD CheckStyle = WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | WS_TABSTOP;
	DWORD RadioStyle = WS_CHILD | WS_VISIBLE | BS_RADIOBUTTON | BS_NOTIFY | WS_TABSTOP;
	DWORD ComBoxStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | CBS_DROPDOWNLIST | WS_TABSTOP;
	 nNumofWord=0;
	 nNumofBit = 0;
	 nNumofMultiBit = 0;
	 nNumOfInt = 0;

	 
	CRect r;
	MyGetRect(IDC_STATIC1, &r);
	SIZEOFSTATICX = r.right - r.left;
	POSEOFSTATICXLEFT = r.left;
	POSEOFSTATICY = r.top;

	MyGetRect(IDC_STATIC2, &r);
	POSEOFSTATICXRIGHT = r.left;

	MyGetRect(IDC_EDIT1, &r);
	SIZEOFEDITX = r.right - r.left;
	POSEOFEDITXLEFT = r.left;
	POSEOFEDITY = r.top;

	MyGetRect(IDC_EDIT2, &r);
	POSEOFEDITXRIGHT = r.left;

	MyGetRect(IDC_GROUP1, &r);
	GROUPWIDTH1 = r.right - r.left;

	MyGetRect(IDC_GROUP3, &r);
	GROUPWIDTH2 = r.right - r.left;
	GROUPXRIGHT = r.left;

	MyGetRect(IDC_CHECK1, &r);
	BUTTONLEFTX = r.left;
	SIZEBUTTONX = r.right - r.left;

	MyGetRect(IDC_CHECK2, &r);
	BUTTONRIGHTX = r.left;

	MyGetRect(IDC_STATIC_DROP, &r);
	SIZEOFCCOMBOX_STATICX = r.right - r.left;
	MyGetRect(IDC_COMBO_DROP, &r);
	SIZEOFCCOMBOX_X = r.right - r.left;
	int radioidx = 0;
	CFont* pFont = GetFont();
	CDC* pDC = GetDC();
	CMFCMaskedEdit *pEdit;


	CStatic *pStatic;
	CButton *pButton;
	BOOL bLeft;
	int i, j, k;
	int nCurX, nCurY;
	int nNextY, nNextY1;
	//	char chTmp[10];
	TCHAR wsztmp[32];
	//	int nTmp;
	int nNumofByte = 0;
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm);
	SIZEOFSTATICY = tm.tmHeight;
	SIZEOFCCOMBOX_Y = tm.tmHeight + 2;
	SIZEOFEDITY = tm.tmHeight + 2;
	SIZEBUTTONY = tm.tmHeight;
	//���Ϊ��
	int IsNotEmpty=0;
	nNextY = POSEOFSTATICY;
	nNextY1 = POSEOFEDITY;
	i = 0; j = 0;
	bLeft = TRUE;
	//CHAR ��ѡ
	if (nSingleIntCnt)
	{

		for (k = 0; k < nSingleIntCnt; k++)
		{
			(pConfigEditOneValue + k)->nValue=g_ConfigData.nData[(pConfigEditOneValue + k)->nPos];
			if (((pConfigEditOneValue + k)->cType == 0) && ((pConfigEditOneValue + k)->nPage == m_nPageIdx))
			{
				nNumofByte++;
				if (bLeft)
					nCurX = POSEOFSTATICXLEFT;
				else
					nCurX = GROUPXRIGHT;
				nCurY = POSEOFSTATICY + i*(SIZEOFSTATICY + INTERNALINTWO);
				makeRect(nCurX, nCurY, SIZEOFSTATICX, SIZEOFSTATICY, r);
				pStatic = new CStatic();
				(pConfigEditOneValue + k)->pStatic = pStatic;

				pStatic->Create((pConfigEditOneValue + k)->chName, StatStyle, r, this);
				pStatic->SetFont(pFont);

				if (bLeft)
					//右对齐radio单选的group外框的右边
					nCurX = POSEOFSTATICXLEFT + GROUPWIDTH2 - (SIZEOFEDITX + 20);
				else
					nCurX = GROUPXRIGHT + GROUPWIDTH2 - (SIZEOFEDITX + 20);
				nCurY = POSEOFEDITY + i*(SIZEOFEDITY + INTERNALINTWO);
				// 
				makeRect(nCurX, nCurY, SIZEOFEDITX+20, SIZEOFEDITY, r);

				pEdit = new CMFCMaskedEdit();
				(pConfigEditOneValue + k)->pEdit = pEdit;
				pEdit->CreateEx(dwEDITEXTYPE, _T("EDIT"), NULL,
					BoxStyle,
					r.left, r.top,
					r.right - r.left, r.bottom - r.top,
					this->GetSafeHwnd(), (HMENU)(BYTEID + 3), (LPVOID)NULL);

				//pEdit->SetFont(pFont);
				//pEdit->SetLimitText(2);

				pEdit->EnableMask(_T("  AA"), _T("0x__"), _T('_'));

				pEdit->SetValidChars(_T("1234567890ABCDEFabcdef"));
				wsprintf(wsztmp, L"0x%02x", (pConfigEditOneValue + k)->nValue);
				pEdit->SetWindowText(wsztmp);

				IsNotEmpty=1;
				if (!bLeft)
					i++;
				bLeft = !bLeft;
				IsNotEmpty=1;
			}

		}
		if(IsNotEmpty)
		{
			nNextY = POSEOFSTATICY + (nNumofByte / 2 + nNumofByte %2)*(SIZEOFEDITY + INTERNALINTWO);
			nNextY1 = POSEOFEDITY + (nNumofByte / 2 + nNumofByte % 2)*(SIZEOFEDITY + INTERNALINTWO);
		}
		
	}
	else
	{
		nNextY = POSEOFSTATICY;
		nNextY1 = POSEOFEDITY;
	}

	i = 0;
	bLeft = TRUE;
	//SHORT �͵�ѡ
	IsNotEmpty=0;
	for (k = 0; k < nSingleIntCnt; k++)
	{

		if (((pConfigEditOneValue + k)->cType == 1) && ((pConfigEditOneValue + k)->nPage == m_nPageIdx))
		{
			if (bLeft)
				nCurX = POSEOFSTATICXLEFT;
			else
				nCurX = GROUPXRIGHT;
			nNumofWord++;
			nCurY = nNextY + i*(SIZEOFEDITY + INTERNALINTWO);
			makeRect(nCurX, nCurY, SIZEOFSTATICX, SIZEOFSTATICY, r);
			pStatic = new CStatic();
			//	(pStaticArr[k]) = pStatic;

			pStatic->Create((pConfigEditOneValue + k)->chName, StatStyle, r, this);
			pStatic->SetFont(pFont);

			if (bLeft)
				nCurX = POSEOFSTATICXLEFT + GROUPWIDTH2 - (SIZEOFEDITX + 20);
			else
				nCurX = GROUPXRIGHT + GROUPWIDTH2 - (SIZEOFEDITX + 20);

			nCurY = nNextY1 + i*(SIZEOFEDITY + INTERNALINTWO);
			makeRect(nCurX, nCurY, SIZEOFEDITX+20, SIZEOFEDITY, r);
			pEdit = new CMFCMaskedEdit();
			(pConfigEditOneValue + k)->pEdit = pEdit;
			pEdit->CreateEx(dwEDITEXTYPE, _T("EDIT"), NULL,
				BoxStyle,
				r.left, r.top,
				r.right - r.left, r.bottom - r.top,
				this->GetSafeHwnd(), (HMENU)(BYTEID + 3), (LPVOID)NULL);

			//pEdit->SetFont(pFont);
			//pEdit->SetLimitText(2);

			pEdit->EnableMask(_T("  AAAA"), _T("0x____"), _T('_'));

			pEdit->SetValidChars(_T("1234567890ABCDEFabcdef"));
			wsprintf(wsztmp, L"0x%04x", (pConfigEditOneValue + k)->nValue);
			pEdit->SetWindowText(wsztmp);

			//			nTmp=nConfigWord[pWord[k].nPos] & 0xffff;
			//			sprintf(chTmp,"%04X",nTmp);
			//			pWord[k].pEdit->SetWindowText(chTmp);

			if (!bLeft)
				i++;
			bLeft = !bLeft;
			IsNotEmpty=1;

		}

	}
	if(IsNotEmpty)
	{	
	
		nNextY = nNextY + (nNumofWord / 2 + nNumofWord % 2) * (SIZEOFEDITY + INTERNALINTWO);
		nNextY1 = nNextY1 + (nNumofWord / 2 + nNumofWord % 2) * (SIZEOFEDITY + INTERNALINTWO);
	}
	
	//nNextY = nNextY + (nNumofWord / 2 + 1)*(SIZEOFEDITY );

	i = 0;
	bLeft = TRUE;
		IsNotEmpty=0;

	//INT
	for (k = 0; k < nSingleIntCnt; k++)
	{

		if (((pConfigEditOneValue + k)->cType == 2) && ((pConfigEditOneValue + k)->nPage == m_nPageIdx))
		{
			if (bLeft)
				nCurX = POSEOFSTATICXLEFT;
			else
				nCurX = GROUPXRIGHT;
			nNumOfInt++;
			nCurY = nNextY + i*(SIZEOFEDITY + INTERNALINTWO);
			makeRect(nCurX, nCurY, SIZEOFSTATICX, SIZEOFSTATICY, r);
			pStatic = new CStatic();
			pStatic->Create((pConfigEditOneValue + k)->chName, StatStyle, r, this);
			pStatic->SetFont(pFont);

			if (bLeft)
				nCurX = POSEOFSTATICXLEFT + GROUPWIDTH2 - (SIZEOFEDITX + 20);
			else
				nCurX = GROUPXRIGHT + GROUPWIDTH2 - (SIZEOFEDITX + 20);

			nCurY = nNextY1 + i*(SIZEOFEDITY + INTERNALINTWO);
			makeRect(nCurX, nCurY, SIZEOFEDITX+20, SIZEOFEDITY, r);
			pEdit = new CMFCMaskedEdit();
			(pConfigEditOneValue + k)->pEdit = pEdit;
			pEdit->CreateEx(dwEDITEXTYPE, _T("EDIT"), NULL,
				BoxStyle,
				r.left, r.top,
				r.right - r.left, r.bottom - r.top,
				this->GetSafeHwnd(), (HMENU)(BYTEID + 3), (LPVOID)NULL);

			//pEdit->SetFont(pFont);
			//pEdit->SetLimitText(2);

			pEdit->EnableMask(_T("  AAAAAAAA"), _T("0x________"), _T('_'));


			pEdit->SetValidChars(_T("1234567890ABCDEFabcdef"));
			wsprintf(wsztmp, L"0x%08x", (pConfigEditOneValue + k)->nValue);
			pEdit->SetWindowText(wsztmp);

			//			nTmp=nConfigWord[pWord[k].nPos] & 0xffff;
			//			sprintf(chTmp,"%04X",nTmp);
			//			pWord[k].pEdit->SetWindowText(chTmp);

			if (!bLeft)
				i++;
			bLeft = !bLeft;
			IsNotEmpty=1;
		}


	}
	if(IsNotEmpty)
	{
		nNextY +=  (nNumOfInt / 2 + nNumOfInt % 2) * (SIZEOFEDITY + INTERNALINTWO);
		nNextY1 += + (nNumOfInt / 2 + nNumOfInt % 2) * (SIZEOFEDITY + INTERNALINTWO);
	}
	i = 0;
	//RADIO
	IsNotEmpty = 0;
	bLeft = TRUE;
	//INT no 0X前缀
	nNumOfInt = 0;
	for (k = 0; k < nSingleIntCnt; k++)
	{

		if (((pConfigEditOneValue + k)->cType == 3) && ((pConfigEditOneValue + k)->nPage == m_nPageIdx))
		{
			if (bLeft)
				nCurX = POSEOFSTATICXLEFT;
			else
				nCurX = GROUPXRIGHT;
			nNumOfInt++;
			nCurY = nNextY + i * (SIZEOFEDITY + INTERNALINTWO);
			makeRect(nCurX, nCurY, SIZEOFSTATICX, SIZEOFSTATICY, r);
			pStatic = new CStatic();
			pStatic->Create((pConfigEditOneValue + k)->chName, StatStyle, r, this);
			pStatic->SetFont(pFont);

			if (bLeft)
				nCurX = POSEOFEDITXLEFT;
			else
				nCurX = POSEOFEDITXRIGHT;

			nCurY = nNextY1 + i * (SIZEOFEDITY + INTERNALINTWO);
			makeRect(nCurX, nCurY, SIZEOFEDITX * 2, SIZEOFEDITY, r);
			
			pEdit = new CMFCMaskedEdit();
			(pConfigEditOneValue + k)->pEdit = pEdit;
			pEdit->CreateEx(dwEDITEXTYPE, _T("EDIT"), NULL,
				BoxStyle,
				r.left, r.top,
				r.right - r.left, r.bottom - r.top,
				this->GetSafeHwnd(), (HMENU)(BYTEID + 3), (LPVOID)NULL);

			//pEdit->SetFont(pFont);
			//pEdit->SetLimitText(2);


			wsprintf(wsztmp, L"%x", (pConfigEditOneValue + k)->nValue);
			pEdit->SetWindowText(wsztmp);

			//			nTmp=nConfigWord[pWord[k].nPos] & 0xffff;
			//			sprintf(chTmp,"%04X",nTmp);
			//			pWord[k].pEdit->SetWindowText(chTmp);

			if (!bLeft)
				i++;
			bLeft = !bLeft;
			IsNotEmpty = 1;
		}


	}
	if (IsNotEmpty)
	{
		nNextY +=   (nNumOfInt / 2 + nNumOfInt % 2) * (SIZEOFEDITY + INTERNALINTWO);
	}
	if (nSingleIntCnt)
	{
		nNextY += INTERNALTOOK;
	}
	//multi check
	i = 0;
	//nNextY += INTERNALINTWO;

	//复选�
		IsNotEmpty=0;
	bLeft = TRUE;
	if (nMultiCnt)
	{
		// 			nCurX = POSEOFSTATICXLEFT;
		// 			nCurY = nNextY;
		// 			makeRect(nCurX, nCurY, GROUPWIDTH1, (SIZEOFEDITY + INTERNALINTWO)*(1 + nNumofBit / 2 + nNumofBit % 2), r);
		// 			pStatic = new CStatic();
		// 			pStatic->Create((pConfigBitMultiValue + k)->chName, StatStyle, r, this);
		// 			pStatic->SetFont(pFont);

		for (k = 0; k < nMultiCnt; k++)
		{
			(pConfigBitMultiValue + k)->nValue = g_ConfigData.nData[(pConfigBitMultiValue + k)->nPos];
			if (((pConfigBitMultiValue + k)->cType == 0) && ((pConfigBitMultiValue + k)->nPage == m_nPageIdx))
			{
				nNumofBit = (pConfigBitMultiValue + k)->nCnt;
				for (j = 0; j < (pConfigBitMultiValue + k)->nCnt; j++)
				{
					if (bLeft)
						nCurX = POSEOFSTATICXLEFT;
					else
						nCurX = GROUPXRIGHT;
					nCurY = nNextY + (i )*(SIZEOFEDITY + INTERNALINTWO);
					makeRect(nCurX, nCurY, SIZEBUTTONX, SIZEBUTTONY, r);

					pButton = new CButton();
					pButton->Create((pConfigBitMultiValue + k)->chSubName[j], CheckStyle, r, this, BITID + k);
					pButton->SetFont(pFont);
					(pConfigBitMultiValue + k)->pButton[j] = pButton;
					if ((pConfigBitMultiValue + k)->nValue&(1 << j))
					{
						pButton->SetCheck(1);
					}
					if (!bLeft)
						i++;
					bLeft = !bLeft;
					IsNotEmpty=1;
				}
				if(IsNotEmpty)
				{
						nNextY = nNextY + ((pConfigBitMultiValue + k)->nCnt / 2 + (pConfigBitMultiValue + k)->nCnt % 2)*(SIZEOFEDITY);	
				}
				




			}

		}
		
		//if (IsNotEmpty)nNextY = nNextY + (nMultiCnt / 2 + nMultiCnt % 2)*(SIZEOFEDITY-3 ) ;
	}
	int CurLeftY , CurRightY ;
	//如果
	if (IsNotEmpty)
	{
		nNextY += INTERNALINTWO + 20;
		
	}
	CurLeftY = nNextY, CurRightY = nNextY;
	int nTmpY;
	//multi Radio
	i = 0;
	//RADIO
	IsNotEmpty = 0;
	bLeft = TRUE;
	if (nMultiCnt)
	{
		for (k = 0; k < nMultiCnt; k++)
		{

			if (bLeft)
			{
				nCurX = POSEOFSTATICXLEFT;
				nCurY = CurLeftY;
			}
			else
			{
				nCurX = GROUPXRIGHT;
				nCurY = CurRightY;
			}

			if (((pConfigBitMultiValue + k)->cType == 1) && ((pConfigBitMultiValue + k)->nPage == m_nPageIdx))
			{

				//nCurY = nTmpY + k*(SIZEOFEDITY + INTERNALINTWO);
				//makeRect(nCurX, nCurY, GROUPWIDTH2, (SIZEOFEDITY + INTERNALINTWO)*(1 + pMultiBit[j].nNumofSmall), r);
				makeRect(nCurX, nCurY, GROUPWIDTH2, (SIZEOFEDITY + INTERNALINTWO)*(1 + (pConfigBitMultiValue + k)->nCnt), r);
				pButton = new CButton();
				pButton->Create((pConfigBitMultiValue + k)->chName, GroupStyle, r, this, 0xffff);
				pButton->SetFont(pFont);
				(pConfigBitMultiValue + k)->pButton[j] = pButton;
				nTmpY = nCurY + (SIZEOFEDITY + INTERNALINTWO);
				for (j = 0; j < (pConfigBitMultiValue + k)->nCnt; j++)
				{
					// 						if (bLeft)
					// 							nCurX = BUTTONLEFTX;
					// 						else
					// 							nCurX = BUTTONRIGHTX;
					nCurY = nTmpY + j*(SIZEOFEDITY + INTERNALINTWO);
					makeRect(nCurX + 10, nCurY, SIZEBUTTONX, SIZEBUTTONY, r);

					pButton = new CButton();
					pButton->Create((pConfigBitMultiValue + k)->chSubName[j], RadioStyle, r, this, BITID + 32 + radioidx++);

					pButton->SetFont(pFont);
					//pButton->SetCheck(1);
					(pConfigBitMultiValue + k)->pButton[j] = pButton;
					if ((pConfigBitMultiValue + k)->nValue&(1 << j))
					{
						pButton->SetCheck(1);
					}
					IsNotEmpty = 1;
				}

				if (bLeft)
					CurLeftY += ((pConfigBitMultiValue + k)->nCnt + 2)*(SIZEOFEDITY + INTERNALINTWO) ;
				else
					CurRightY += ((pConfigBitMultiValue + k)->nCnt + 2)*(SIZEOFEDITY + INTERNALINTWO) ;

				if (IsNotEmpty && (TRUE == bLeft))
				{
					nNextY = nCurY + ((pConfigBitMultiValue + k)->nCnt / 2 + (pConfigBitMultiValue + k)->nCnt % 2) * (SIZEOFEDITY);
				}

				bLeft = !bLeft;
				
				
			}

			
		}
		//nNextY = nNextY + (nNumofBit / 2 + 1 + 1)*(SIZEOFEDITY + INTERNALINTWO);
	}
	if (IsNotEmpty)
	{
		nNextY += INTERNALINTWO + 40;
		
	}
	CurLeftY = nNextY, CurRightY = nNextY;
	
	//multi NEW CHECKBOX
	i = 0;
	IsNotEmpty = 0;

	//NEW CHECKBOX
	bLeft = TRUE;

	if (nMultiCnt)
	{
		for (k = 0; k < nMultiCnt; k++)
		{

			if (bLeft)
			{
				nCurX = POSEOFSTATICXLEFT;
				nCurY = CurLeftY;
			}
			else
			{
				nCurX = GROUPXRIGHT;
				nCurY = CurRightY;
			}

			if (((pConfigBitMultiValue + k)->cType == 2) && ((pConfigBitMultiValue + k)->nPage == m_nPageIdx))
			{

				//nCurY = nTmpY + k*(SIZEOFEDITY + INTERNALINTWO);
				//makeRect(nCurX, nCurY, GROUPWIDTH2, (SIZEOFEDITY + INTERNALINTWO)*(1 + pMultiBit[j].nNumofSmall), r);
				makeRect(nCurX, nCurY, GROUPWIDTH2, (SIZEOFEDITY + INTERNALINTWO) * (1 + (pConfigBitMultiValue + k)->nCnt), r);
				pButton = new CButton();
				pButton->Create((pConfigBitMultiValue + k)->chName, GroupStyle, r, this, 0xffff);
				pButton->SetFont(pFont);
				(pConfigBitMultiValue + k)->pButton[j] = pButton;
				nTmpY = nCurY + (SIZEOFEDITY + INTERNALINTWO);
				for (j = 0; j < (pConfigBitMultiValue + k)->nCnt; j++)
				{
					// 						if (bLeft)
					// 							nCurX = BUTTONLEFTX;
					// 						else
					// 							nCurX = BUTTONRIGHTX;
					nCurY = nTmpY + j * (SIZEOFEDITY + INTERNALINTWO);
					makeRect(nCurX + 10, nCurY, SIZEBUTTONX, SIZEBUTTONY, r);

					pButton = new CButton();
					pButton->Create((pConfigBitMultiValue + k)->chSubName[j], CheckStyle, r, this, BITID + 32 + radioidx++);

					pButton->SetFont(pFont);
					//pButton->SetCheck(1);
					(pConfigBitMultiValue + k)->pButton[j] = pButton;
					if ((pConfigBitMultiValue + k)->nValue &(1 << j))
					{
						pButton->SetCheck(1);
					}
				}

				if (bLeft)
					CurLeftY += ((pConfigBitMultiValue + k)->nCnt + 2) * (SIZEOFEDITY + INTERNALINTWO) + INTERNALINTWO;
				else
					CurRightY += ((pConfigBitMultiValue + k)->nCnt + 2) * (SIZEOFEDITY + INTERNALINTWO) + INTERNALINTWO;

				bLeft = !bLeft;


			}

		}
		//nNextY = nNextY + (nNumofBit / 2 + 1 + 1)*(SIZEOFEDITY + INTERNALINTWO);
	}

	CMainFrame * pMainFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd;

	if (pMainFrame->m_bIsPrjEditable == FALSE)
	{
		EnableChildWindow(this, FALSE);
	}
	

	return CPropertyPage::OnSetActive();
}
